package com.mediacloud.app.newsmodule.activity.military_encyclopedia

import android.app.Dialog
import android.content.Context
import android.content.DialogInterface
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.Window
import android.widget.LinearLayout
import android.widget.RelativeLayout
import android.widget.TextView
import com.mediacloud.app.newsmodule.R
import com.mediacloud.appcloud.project.gxapp.view.widget.CommonDialog

/**
 * 标注弹窗
 * @constructor
 */
class MarkingDialog(context: Context):Dialog(context, R.style.CustomCommonDialogX) {


    class Builder {
        private var context: Context? = null
        private var title: String? = null
        private var message: String? = null
        private var clickListener: View.OnClickListener? = null
        fun builder(context: Context?): Builder {
            this.context = context
            return this
        }

        fun setTitle(title: String?): Builder {
            this.title = title
            return this
        }

        fun setMsg(message: String?): Builder {
            this.message = message
            return this
        }
        fun setClick(click: View.OnClickListener?): Builder {
            this.clickListener = click
            return this
        }

        fun create(): CommonDialog {
            val dialog = CommonDialog(context!!, R.style.CustomCommonDialogX)
            val view = LayoutInflater.from(context).inflate(R.layout.dialog_marking, null)
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE)
            dialog.setCanceledOnTouchOutside(true)
            val layoutParams = LinearLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT
            )
            layoutParams.leftMargin = 45
            layoutParams.rightMargin = 45
            dialog.setContentView(view, layoutParams)
            dialog.window!!.setBackgroundDrawableResource(android.R.color.transparent)
            val tvTite = view.findViewById<TextView>(R.id.tv_title)
            val tvMsg = view.findViewById<TextView>(R.id.tv_msg)
            tvMsg.text = message
            tvTite.text = title
            view.findViewById<RelativeLayout>(R.id.dialogLayout).setOnClickListener {
                dialog.dismiss()
                clickListener?.onClick(it)
            }
            return dialog
        }
    }
    override fun show() {
        super.show()
        val window = window
        val params = window!!.attributes
        params.width = -1
        window.attributes = params
    }
}